package reflect;

import java.lang.reflect.Field;

/**
 * 反射机制操作属性
 */
public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
       Teacher t=new Teacher();
       t.name="万历";
        System.out.println(t.name);
        System.out.println(t);

        Class cls=Class.forName("reflect.Teacher");
        Object obj=cls.newInstance();

        Field field=cls.getField("name");
        field.set(obj,"守财");
        System.out.println(field.get(obj));
        System.out.println(obj);

    }
}
